package com.starsoft.quant.executor;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.starsoft.frame.util.DateUtil;
import com.starsoft.quant.analysis.IndicatorService;
import com.starsoft.quant.analysis.VolatilityService;
import com.starsoft.quant.bean.ModelContext;
import com.starsoft.quant.service.QuantReportService;
import com.starsoft.smdc.bean.SmdcEr;
import com.starsoft.smdc.bean.SmdcHandicap;
import com.starsoft.smdc.bean.SmdcMarketDaily;
import com.starsoft.smdc.bean.SmdcSecurity;
import com.starsoft.smdc.crawler.common.HandicapCrawler;
import com.starsoft.smdc.crawler.common.HandicapCrawlerImpl;
import com.starsoft.smdc.crawler.eastmoney.FundNavPreEastmoney;
import com.starsoft.smdc.service.DivService;
import com.starsoft.smdc.service.ErService;
import com.starsoft.smdc.service.HolidayService;
import com.starsoft.smdc.service.MarketDailyService;
import com.starsoft.smdc.service.SecurityService;
import com.starsoft.trade.bean.TradeAcountStatus;
import com.starsoft.trade.service.TradeBillService;

public class ExecutorContext {

	private ModelContext modelContext;
	private ExecutMode executMode;
	private Date currentDate;
	private TradeAcountStatus acountStatus;
	private List<SmdcSecurity> securityListNoFilter;
	private List<SmdcSecurity> securityList;
	private Map<String, SmdcHandicap> handicapMap;
	private Map<String, SmdcMarketDaily> marketDailyMap;
	private Map<String, SmdcEr> erMap;
	private StrategyReport lastReport;
	private StringBuilder runLog;

	private SecurityService securityService;
	private HandicapCrawlerImpl handicapService;
	private DivService divService;
	private ErService erService;
	private ExecutorService orderService;
	private QuantReportService reportService;
	private HolidayService holidayService;
	private MarketDailyService marketDailyService;
	private TradeBillService tradeBillService;
	private FundNavPreEastmoney fundNavPreService;
	
	private IndicatorService indicatorService;
	private VolatilityService volatilityService;

	public enum ExecutMode {
		TRADE_TIME, SPECIFY_TIME, BACK_TEST
	}

	public ModelContext getModelContext() {
		return modelContext;
	}

	public void setModelContext(ModelContext modelContext) {
		this.modelContext = modelContext;
	}

	public SecurityService getSecurityService() {
		return securityService;
	}

	public void setSecurityService(SecurityService securityService) {
		this.securityService = securityService;
	}

	public Date getCurrentDate() {
		return currentDate;
	}

	public void setCurrentDate(Date currentDate) {
		this.currentDate = currentDate;
	}

	public HandicapCrawlerImpl getHandicapService() {
		return handicapService;
	}

	public void setHandicapService(HandicapCrawlerImpl handicapService) {
		this.handicapService = handicapService;
	}
	
	public List<SmdcSecurity> getSecurityListNoFilter() {
		return securityListNoFilter;
	}

	public void setSecurityListNoFilter(List<SmdcSecurity> securityListNoFilter) {
		this.securityListNoFilter = securityListNoFilter;
	}

	public List<SmdcSecurity> getSecurityList() {
		return securityList;
	}

	public void setSecurityList(List<SmdcSecurity> securityList) {
		this.securityList = securityList;
	}

	public Map<String, SmdcHandicap> getHandicapMap() {
		return handicapMap;
	}

	public void setHandicapMap(Map<String, SmdcHandicap> handicapMap) {
		this.handicapMap = handicapMap;
	}

	/**
	 * @param funda
	 * @return
	 */
	public SmdcHandicap getHandicap(SmdcSecurity funda) {
		return handicapMap.get(funda.getSecId());
	}

	public SmdcMarketDaily getMarket(String secId) {
		return marketDailyMap.get(secId);
	}

	public Map<String, SmdcMarketDaily> getMarketDailyMap() {
		return marketDailyMap;
	}

	public void setMarketDailyMap(Map<String, SmdcMarketDaily> marketDailyMap) {
		this.marketDailyMap = marketDailyMap;
	}

	public ExecutMode getExecutMode() {
		return executMode;
	}

	public void setExecutMode(ExecutMode executMode) {
		this.executMode = executMode;
	}

	public Map<String, SmdcEr> getErMap() {
		return erMap;
	}

	public void setErMap(Map<String, SmdcEr> erMap) {
		this.erMap = erMap;
	}

	public SmdcEr getEr(SmdcSecurity security) {
		return erMap.get(security.getSecId());
	}

	public DivService getDivService() {
		return divService;
	}

	public void setDivService(DivService divService) {
		this.divService = divService;
	}

	public ErService getErService() {
		return erService;
	}

	public void setErService(ErService erService) {
		this.erService = erService;
	}

	public TradeAcountStatus getAcountStatus() {
		return acountStatus;
	}

	public void setAcountStatus(TradeAcountStatus acountStatus) {
		this.acountStatus = acountStatus;
	}

	public ExecutorService getOrderService() {
		return orderService;
	}

	public void setOrderService(ExecutorService orderService) {
		this.orderService = orderService;
	}

	public QuantReportService getReportService() {
		return reportService;
	}

	public void setReportService(QuantReportService reportService) {
		this.reportService = reportService;
	}

	public HolidayService getHolidayService() {
		return holidayService;
	}

	public void setHolidayService(HolidayService holidayService) {
		this.holidayService = holidayService;
	}

	public StrategyReport getLastReport() {
		return lastReport;
	}

	public void setLastReport(StrategyReport lastReport) {
		this.lastReport = lastReport;
	}

	public StringBuilder getRunLog() {
		return runLog;
	}

	public void setRunLog(StringBuilder runLog) {
		this.runLog = runLog;
	}

	public MarketDailyService getMarketDailyService() {
		return marketDailyService;
	}

	public void setMarketDailyService(MarketDailyService marketDailyService) {
		this.marketDailyService = marketDailyService;
	}
	
	public IndicatorService getIndicatorService() {
		return indicatorService;
	}

	public void setIndicatorService(IndicatorService indicatorService) {
		this.indicatorService = indicatorService;
	}
	
	public TradeBillService getTradeBillService() {
		return tradeBillService;
	}

	public void setTradeBillService(TradeBillService tradeBillService) {
		this.tradeBillService = tradeBillService;
	}
	
	public FundNavPreEastmoney getFundNavPreService() {
		return fundNavPreService;
	}

	public void setFundNavPreService(FundNavPreEastmoney fundNavPreService) {
		this.fundNavPreService = fundNavPreService;
	}
	
	public VolatilityService getVolatilityService() {
		return volatilityService;
	}

	public void setVolatilityService(VolatilityService volatilityService) {
		this.volatilityService = volatilityService;
	}

	public boolean isBackTest() {
		return executMode == ExecutMode.BACK_TEST;
	}

	public boolean isTradeTime() {
		return executMode == ExecutMode.TRADE_TIME;
	}

	public boolean isToday() {
		return DateUtil.isToday(currentDate);
	}
	
}
